﻿using FRRJIf;
using RJi.FanucInterface3.Common.Internal;
using RJi.FanucInterface3.Models;

namespace RJi.FanucInterface3.DataParser.Internal;

internal class DataTaskParser : IDataParser
{
    public bool CanHandle(VariableMetadata metadata)
    {
        return metadata.DataType == typeof(DataTask);
    }

    public object? Parse(VariableMetadata metadata)
    {
        var task = (DataTask)metadata.VariableRef;
        string progName = null!;
        short lineNumber = 0;
        short state = 0;
        string parentProgName = null!;

        return task.GetValue(ref progName, ref lineNumber, ref state, ref parentProgName)
            ? new RbtTask(task.Index, progName, lineNumber, state, parentProgName)
            : null;
    }
}